package com.service.Impl;

import com.dao.UserDao;
import com.mypg.MyPage;
import com.mypg.User;
import com.service.UserQuestionService;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class UserServiceImpl implements UserService {

    private UserDao userDao;

    private UserQuestionService userQuestionService;

    public UserServiceImpl(){}

    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    public UserServiceImpl(UserDao userDao, UserQuestionService userQuestionService) {
        this.userDao = userDao;
        this.userQuestionService = userQuestionService;
    }

    @Override
    public List<User> selectAllUser() {
        return userDao.selectAllUser();
    }

    @Override
    public List<User> selectUserByPage(int start_row, int end_row) {
        MyPage page=new MyPage(start_row,end_row);
        return userDao.selectUserByPage(page);
    }

    @Override
    public User selectUserByUser_id(int user_id) {
        User user=new User();
        user.setUser_id(user_id);
        return userDao.selectUserByUser_id(user);
    }

    @Override
    public User selectUserByUser_name(String user_name) {
        User user=new User();
        user.setUser_name(user_name);
        return userDao.selectUserByUser_name(user);
    }

    @Override
    public int selectUser_count() {
        return userDao.selectUser_count();
    }

    @Override
    public void insertUser(User user) {
        userDao.insertUser(user);
    }

    @Override
    public void insertUserByUser_id(User user) {
        userDao.insertUserByUser_id(user);
    }

    @Override
    public void insertUserByUser_name(User user) {
        userDao.insertUserByUser_name(user);
    }

    @Override
    public void updateUserByUser_id(User user) {
        userDao.updateUserByUser_id(user);
        userQuestionService.updateUser_nicknameByUser_id(user.getUser_id(),user.getUser_nickname());
    }

    @Override
    public void updateUserByUser_name(User user) {
        userDao.updateUserByUser_name(user);
        userQuestionService.updateUser_nicknameByUser_id(user.getUser_id(),user.getUser_nickname());
    }

    @Override
    public void updateUser_imgByUser_name(String user_name, String user_img) {
        userDao.updateUser_imgByUser_name(user_name,user_img);
    }

    @Override
    public void deleteUserByUser_id(int user_id) {
        User user=new User();
        user.setUser_id(user_id);
        userDao.deleteUserByUser_id(user);
    }

    @Override
    public void deleteUserByUser_name(String user_name) {
        User user=new User();
        user.setUser_name(user_name);
        userDao.deleteUserByUser_name(user);
    }

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public UserQuestionService getUserQuestionService() {
        return userQuestionService;
    }

    public void setUserQuestionService(UserQuestionService userQuestionService) {
        this.userQuestionService = userQuestionService;
    }
}
